Introduction

The two words I used were: “colourful painting” because art can have many different interpretations and results. Therefore, with these two words, I was hoping to get a variety of different paintings and colours instead of just one result repeated over and over.

This is the photo of the first few rows of royalty free photos:

It seems like most of the photos I saw on the website were landscape or 1:1 aspect ratios. The tags I spotted the most were “art” and “brushes” as expected for a result about paintings. One of the photos had 900 likes but seemingly most of the others had less than 300 likes. Many of the photos have seem to have brushes and colouring utensils that complement the painting itself.

photo_data %>%
  select(pageURL) %>%
  knitr::kable(format = "html")
pageURL
https://pixabay.com/photos/colorful-painting-background-2468874/
https://pixabay.com/photos/girl-face-colorful-colors-artistic-2696947/
https://pixabay.com/photos/paint-makeup-girl-cosmetics-2985569/
https://pixabay.com/photos/color-acrylic-paint-art-painting-4158152/
https://pixabay.com/photos/art-watercolors-arts-and-crafts-1851483/
https://pixabay.com/photos/watercolor-painting-colorful-art-2681039/
https://pixabay.com/photos/brushes-painter-work-shop-bowl-3129361/
https://pixabay.com/photos/art-paint-water-colors-desk-artist-1209519/
https://pixabay.com/photos/mountain-colors-paint-colorful-art-6538890/
https://pixabay.com/photos/art-multicoloured-to-dye-abstract-2369664/
https://pixabay.com/photos/abstract-painting-feathers-6047465/
https://pixabay.com/photos/paper-brush-color-palette-painting-3204064/
https://pixabay.com/photos/brush-paint-color-watercolor-art-96240/
https://pixabay.com/photos/woman-beauty-light-painting-light-6046019/
https://pixabay.com/photos/gallery-art-mural-baroque-3114279/
https://pixabay.com/photos/hearts-paint-brush-painting-love-6963368/
https://pixabay.com/photos/to-dye-watercolor-colour-5821297/
https://pixabay.com/photos/art-art-supplies-artist-blue-brush-1478831/
https://pixabay.com/photos/graffiti-wall-mural-painting-569265/
https://pixabay.com/photos/girl-colors-holi-festival-child-3194977/
https://pixabay.com/photos/art-brushes-colorful-paint-1840481/
https://pixabay.com/photos/makeup-face-woman-portrait-girl-2983550/
https://pixabay.com/photos/woman-face-light-painting-light-6174830/
https://pixabay.com/photos/watercolor-colour-art-paint-brush-3445376/
https://pixabay.com/photos/paint-makeup-girl-cosmetics-2990357/
https://pixabay.com/photos/woman-face-light-painting-light-6217377/
https://pixabay.com/photos/eggs-easter-easter-eggs-egg-carton-3216877/
https://pixabay.com/photos/holi-girl-indian-india-dance-fun-2416686/
https://pixabay.com/photos/hands-words-meaning-fingers-423794/
https://pixabay.com/photos/easter-eggs-basket-color-colored-1231120/
https://pixabay.com/photos/brushes-chalks-colorful-2927793/
https://pixabay.com/photos/houses-boats-street-canal-venice-1622066/
https://pixabay.com/photos/wood-colorful-red-orange-yellow-8196/
https://pixabay.com/photos/easter-eggs-basket-easter-eggs-2093315/
https://pixabay.com/photos/spray-cans-colour-paint-cans-3349588/
https://pixabay.com/photos/manicure-pedicure-cosmetics-care-870857/
https://pixabay.com/photos/painting-watercolor-paint-paper-2407262/
https://pixabay.com/photos/green-art-wood-sharp-pencil-group-1738220/
https://pixabay.com/photos/face-painting-colorful-woman-2848057/
https://pixabay.com/photos/colored-pencils-to-paint-heart-4031668/
https://pixabay.com/photos/background-art-abstract-watercolor-3516145/
https://pixabay.com/photos/palette-paints-oil-painting-1482678/
https://pixabay.com/photos/abstract-ink-water-colors-3866486/
https://pixabay.com/photos/heart-valentine-love-affection-red-4169573/
https://pixabay.com/photos/abstract-ink-that-colors-3866485/
https://pixabay.com/photos/paint-brush-to-dye-canvas-3222629/
https://pixabay.com/photos/easter-eggs-easter-eggs-3131188/
https://pixabay.com/photos/watercolor-background-design-paper-795161/
https://pixabay.com/photos/athens-art-school-raphael-1143741/
https://pixabay.com/photos/banner-easter-egg-colored-1255730/
https://pixabay.com/photos/colored-pencils-colour-pencils-374771/
https://pixabay.com/photos/back-to-school-pencils-rainbow-art-1576791/
https://pixabay.com/photos/watercolor-background-design-795156/
https://pixabay.com/photos/toys-frame-puzzle-rubber-duck-3200969/

Key features of selected photos

options(scipen=999) # Remove scientific notation.

mean_downloads = mean(photo_data$downloads) %>%
  round()
median_views = median(photo_data$views) %>%
  round()
mean_comments = mean(photo_data$comments) %>%
  round()

mean_likes = mean(photo_data$likes) %>%
  round()

The mean downloads in my photo data set was \(228846 \ downloads\)

The median amount of views in photo data set was \(168281 \ views.\)

The mean amount of comments for the photos in my set was \(98 \ comments.\)

The mean amount of likes for the photos in my data set was \(611 \ likes.\)

Creativity

For my creativity section, I decided to use a random seed to make a random gif using the data in my selected_photos. By changing the set.seed from the ‘2199’ that I have set it to by default, my code will make a completely different gif. Firstly, set.seed is as a sort of random number generator. Then I use a for loop to create 4 random values between 1 and the length of my data set. These 4 random values are then put into a vector and are then used to pick out photos from selected_photos to create a gif. By changing the set.seed value, the values selected for the vector are different and thus the photos picked out from selected_photos is different and thus a different gif is made.

Learning reflection

I learned what JSON (Javascript Object Notation) is and how to use functions from the jsonlite library, such as the fromJSON function, to be able to use JSON urls. I have learned how to take JSON data and select only the rows I require and add extra rows that I would like to work with using the select() and mutate() functions. I have also learned how to use group_by() and summarise() to summarise data frames as groups.

I would like to learn more about Javascript itself and how to use it with HTML and R. I would also like to further learn more about APIs and how they work. How does the API we used at the beginning work. I have heard of APIs being used in websites as a way to connect one service to another but how does that connection occur and what are the security considerations that go along with it.

Appendix

library(tidyverse)
library(jsonlite)
library(magick)
json_data <- fromJSON("pixabay_data.json")
pixabay_photo_data <- json_data$hits

# Having a look at the raw data.
#pixabay_photo_data %>%
  #view()


# is_popular checks if people liked the photo enough to download, with 100000 being my chosen threshold
# hooks_viewers sees if people get hooked by the photo to click and view it with 200000 being my chosen threshold
# user_interaction_score multiplies likes and comments to make a score for photo activity
selected_photos = pixabay_photo_data %>%
  select(pageURL, previewURL, tags, views, downloads, likes, comments) %>%
  mutate(is_popular = ifelse(downloads > 100000, "Popular", "Not Popular"),
         hooks_viewers = ifelse(views > 200000, "yes", "no"),
         user_interaction_score = (likes * comments) / 1000) %>%
  # We then filter out the photos least interacted with, leaving us with 54 results.
  filter(user_interaction_score > 10)

#Writing out selected photos to selected_photos.csv
write_csv(selected_photos, "selected_photos.csv")

# Calculating means and median values for downloads, views and comments
mean_downloads = mean(selected_photos$downloads) %>%
  round()

median_views = median(selected_photos$views) %>%
  round()

mean_comments = mean(selected_photos$comments) %>%
  round()


# We want to see the avg user interaction score for popular and non-popular photos
summary_value = selected_photos %>%
  group_by(is_popular) %>%
  summarise(avg_UI_score = round(mean(user_interaction_score))) %>%
  print()
  
# Setup the images for the gif
image_1 = image_read(selected_photos$previewURL[1]) %>%
  image_extent("200x200")

image_2 = image_read(selected_photos$previewURL[2]) %>%
  image_extent("200x200")

image_3 = image_read(selected_photos$previewURL[3]) %>%
  image_extent("200x200")

image_4 = image_read(selected_photos$previewURL[4]) %>%
  image_extent("200x200")

# Setup the animation of the images
gif_normal = image_resize(c(image_1, image_2, image_3, image_4)) %>%
  image_morph(frames = 24) %>%
  image_animate(fps = 5, delay = 20, optimize = TRUE)

# Write the gif to my_photos.gif
image_write(gif_normal, "my_photos.gif")


# Creative GIF creation:

# Setting up a random seed, to see a different set of gifs animated, change the seed.
set.seed(2199)

# Initialise a vector
random_values = c()

#Using a for loop to create 4 random values and add them into my vector.
for (i in 1:4){
  random_value = runif(1, min = 1, max = 54)
  random_values = c(random_values, round(random_value))
}

# Setup the random images
random_image_1 = image_read(selected_photos$previewURL[random_values[1]]) %>%
  image_extent("200x200")

random_image_2 = image_read(selected_photos$previewURL[random_values[2]]) %>%
  image_extent("200x200")

random_image_3 = image_read(selected_photos$previewURL[random_values[3]]) %>%
  image_extent("200x200")

random_image_4 = image_read(selected_photos$previewURL[random_values[4]]) %>%
  image_extent("200x200")

# Setup the animation of the random images
gif_random = image_resize(c(random_image_1, random_image_2, random_image_3, random_image_4)) %>%
  image_morph(frames = 24) %>%
  image_animate(fps = 5, delay = 20, optimize = TRUE)

image_write(gif_random, "random_photos.gif")